/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.images;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;

/**
 * <p>Project: jse2204 - LogoWaterDemo
 * <p>Powered by webrx On 2022-09-26 14:52:14
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class LogoWaterDemo {
    public static void main(String[] args) throws Exception {
        String imgs = "c:/abc/g1.jpg";
        //加载要添加水印图标的原图
        BufferedImage src = ImageIO.read(new File(imgs));
        int sw = src.getWidth();
        int sh = src.getHeight();

        //加载logo.png
        BufferedImage logo = ImageIO.read(new File("fonts/logo.png"));
        int logow = logo.getWidth();
        int logoh = logo.getHeight();


        Graphics2D g = src.createGraphics();
        int x = (sw - logow) / 2;
        int y = (sh - logoh) / 2;

        x = sw-logow -10;
        y = sh - logoh - 10;


        //控制水银图标文件的透明度
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP,.3f));

        g.drawImage(logo, x, y, null);
        g.dispose();

        imgs = "c:/abc/g1_logo.jpg";
        ImageIO.write(src, "jpg", new File(imgs));
        Runtime.getRuntime().exec("cmd /k start " + imgs);


    }
}
